<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>买票需要的时间</title>
</head>
<body>
  <script>
    function fn(arr, k) {
      let s = 0
      for (let i = 0; i < arr.length; i++)
        s += Math.min(arr[i], i <= k ? arr[k] : arr[k] - 1)
      return s
    }
    console.log(fn([2, 3, 2], 2))
  </script>
</body>
</html>